package com.t2t.top;

import java.lang.reflect.Field;

/**
 * Created by yangpengfei on 2016/9/6.
 */
public class JVMDirectMemoryTest {
    public static void main(String[] args) throws Exception {
        Class<?> c = Class.forName("java.nio.Bits");
        Field maxMemory = c.getDeclaredField("maxMemory");
        maxMemory.setAccessible(true);
        Field reservedMemory = c.getDeclaredField("reservedMemory");
        reservedMemory.setAccessible(true);
        Long maxMemoryValue = (Long) maxMemory.get(null);
        Long reservedMemoryValue = (Long) reservedMemory.get(null);
        System.out.println("直接内存大小：" + maxMemoryValue / 1024 / 1024);
        System.out.println(reservedMemoryValue);
    }
}
